/*
 * @Autor: Ruohong Yu
 * @Date: 2023-04-01 12:50:23
 * @Description: file content
 * @FilePath: \ebookd:\program\vsc\ebook\node-ebook\schema\user.js
 */
// 导入定义验证规则的包
const joi = require('joi')

// 定义用户名和密码的验证规则
const username = joi.string().pattern(/^\w{2,10}$/).required()
const password = joi
  .string()
  .required()
  // .pattern(/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9]{8,10}$/)

// 定义 email 的验证规则
const user_email = joi.string().email().required()

// 定义验证 avatar 头像的验证规则
const emailcode = joi.string().required()

// 定义验证 avatar 头像的验证规则
const avatar = joi.string().dataUri().required()

// 定义验证注册和登录表单数据的规则对象
exports.reg_login_schema = {
  body: {
    username,
    password,
  },
}

exports.reg_register_schema = {
  body: {
    username,
    password,
    email: user_email
  },
}

// 验证规则对象 - 更新密码
exports.email_schema = {
  body: {
    email: user_email,
  },
}

// 验证规则对象 - 更新用户基本信息
exports.update_userinfo_schema = {
  // 需要对 req.body 里面的数据进行验证
  body: {
    reusername:username,
    email: user_email,
    username
  },
}

// 验证规则对象 - 更新密码
exports.update_password_schema = {
  body: {
    email: user_email,
    password: password,
    emailcode: emailcode
  },
}

// 验证规则对象 - 更新头像
exports.update_avatar_schema = {
  body: {
    avatar
  }
}
